<template>
  <div>
    <a-card class="card-header">
      <a-form-model :model="queryParam">
        <a-row :gutter="24">
          <a-col :span="5">
            <a-form-model-item
              label="仓库名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                v-model.trim="queryParam.wareHouseName"
                placeholder="请输入仓库名称"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="2">
            <a-button
              type="primary"
              style="margin-top:3px"
              @click="handleSearch('wareHouseTypeCode')"
              >查询</a-button
            >
          </a-col>
        </a-row>
      </a-form-model>
    </a-card>

    <a-card class="card-content">
      <a-row :gutter="24">
        <a-col :span="22">
          <a-button type="primary" @click="handleAdd">新建</a-button>
          <!-- <a-button
            type="primary"
            @click="handelExport('仓库管理列表', 'wareHousePage')"
            >导出</a-button
          >
          <a-button type="primary" @click="handleAdd">导入</a-button> -->
        </a-col>
        <a-col :span="2">
          <a-button type="primary" @click="handleAllList('wareHousePage')"
            >全部仓库</a-button
          >
        </a-col>
      </a-row>
      <br />
      <a-row :gutter="16">
        <a-col>
          <a-table
            :columns="columns"
            :data-source="tableData"
            :loading="loading"
            :pagination="pagination"
            @change="handleTableChange"
            bordered
            :rowKey="
              (record, index) => {
                return index;
              }
            "
          >
            <template slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>
              <a-divider type="vertical" v-hasPromise="'warehouseDel'" />
              <a-popconfirm
                v-hasPromise="'warehouseDel'"
                okText="确定"
                cancelText="取消"
                title="确定删除吗?"
                @confirm="() => handleDelete(record)"
              >
                <a>删除</a>
              </a-popconfirm>
            </template>
          </a-table>
        </a-col>
      </a-row>
    </a-card>

    <WarehouseModal
      ref="modalForm"
      @ok="modalFormOk"
      :treeData="treeData"
    ></WarehouseModal>
  </div>
</template>

<script>
import { columns } from "./components/tableConfig";
import { tableMinxins } from "@/unit/mixins/tableMinxins.js";
import WarehouseModal from "@/components/WarehouseModal.vue";
import api from "@/api/apiServer";
export default {
  components: { WarehouseModal },
  mixins: [tableMinxins],
  data() {
    return {
      columns,
      treeData: [],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 获取列表数据
    async getList(arg) {
      //加载数据 若传入参数1则加载第一页的内容
      this.loading = true;
      if (arg === 1) {
        this.pagination.current = 1;
      }
      var params = this.getQueryParams();
      const res = await api.wareHousePage(params);
      this.tableData = res.data.data;
      this.pagination.total = res.data.total;
      this.loading = false;
    },
    // 删除
    async handleDelete(record) {
      const res = await api.wareHouseDelete({
        id: record.id,
      });
      this.getList();
      this.$message.success(res.message);
    },
  },
};
</script>

<style lang="less" scoped>
.card-header {
  margin: 20px 0;
}
.card-content {
  button {
    margin-right: 20px;
  }
}
::v-deep .ant-tree-node-content-wrapper {
  width: 90%;
}
::v-deep .ant-form-item {
  margin-bottom: 0;
}
</style>
